package operations;

import bookList.Book;
import bookList.BookList;

import java.util.Arrays;
import java.util.Scanner;

/**
 * The type Add operation.
 *
 * @author CY
 * @date 2022 /08/09 23:41
 */
public class AddOperation implements Operations {
    @Override
    public void work(BookList bookList) {
        System.out.println("新增图书！");
        Scanner sc = new Scanner(System.in);

        System.out.println("请输入name:");
        String name = sc.nextLine();

        System.out.println("请输入author:");
        String author = sc.nextLine();

        System.out.println("请输入type:");
        String type = sc.nextLine();

        System.out.println("请输入price:");
        int price = sc.nextInt();


        Book book = new Book(name, author, price, type);
        Book[] books = Arrays.copyOf(bookList.getBooks(), bookList.getUsedSize() + 1);
        books[bookList.getUsedSize()] = book;
        bookList.setBooks(books);
        bookList.setUsedSize(bookList.getUsedSize() + 1);
        System.out.println();

    }
}
